package com.kaili.basic;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.kaili.basic.controller.BaseBarcodeRuleController;
import com.kaili.common.response.ResponseBodyWrapFactoryBean;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

/**
 * MDM子站
 * @Copyright: Copyright (c) 2017
 * @Company: 杭州凯立通信有限公司
 * @author zhengs
 * @version 1.0.0 2017年7月23日 下午1:51:40
 */
@ComponentScan(basePackages = "com.kaili.basic,com.kaili.common.aop,com.kaili.common.exception")
@EnableDiscoveryClient
@SpringBootApplication
@EnableAsync
@EnableTransactionManagement(proxyTargetClass = true)
public class BasicServer {
	public static void main(String[] args) {
		new SpringApplicationBuilder(BasicServer.class).web(true).run(args);
		System.out.println("-----------------------------"+BaseBarcodeRuleController.class.getAnnotation(RequestMapping.class));
	}

	/**
	 * mybatis-plus 分页插件
	 */
	@Bean
	public PaginationInterceptor paginationInterceptor() {
		PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
		paginationInterceptor.setLocalPage(true);
		paginationInterceptor.setDialectType("mysql");

		return paginationInterceptor;
	}

	/**
	 * 返回值包装
	 */
	@Bean
	public ResponseBodyWrapFactoryBean getResponseBodyWrap() {
		return new ResponseBodyWrapFactoryBean();
	}

	/*
	 * RestTemplate用于服务间的调用
	 */
	@Bean
	@LoadBalanced
	RestTemplate restTemplate(){
		return new RestTemplate();
	}
}
